<template>
  <div
    :class="`custom-card ${
      type == 'task' ? 'task-color task-bg' : 'shopping-color shopping-bg'
    }`"
  >
    <div>
      <span>{{ year }}</span>
      <span>{{ time }}</span>
    </div>
    <div>
      <span>{{ type == "task" ? "打卡" : "消费" }}内容</span>
      <span>{{ item.content }}</span>
    </div>
    <div>
      <span>打卡金额</span>
      <van-space align="center"
        ><van-icon
          name="gold-coin"
          :color="type == 'task' ? '#78669c' : '#F2B275'"
        />
        {{ type == "task" ? "+" : "-" }}
        {{ Number(item.price) / 100 }}</van-space
      >
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
import { computed } from "vue";
export default {
  props: {
    item: {
      type: Object,
      default: {},
    },
    type: {
      //Card类型 - task / shopping
      type: String,
      default: "task",
    },
  },
  setup(props) {
    const year = computed(() => {
      return dayjs(props.item.time).format("YYYY-MM-DD");
    });
    const time = computed(() => {
      return dayjs(props.item.time).format("HH:ss");
    });
    return { year, time };
  },
};
</script>

<style lang="less" scoped>
.task-color {
  border: 2px solid #78669c;
}
.task-bg {
  background: linear-gradient(
      rgba(255, 255, 255, 0.2),
      /* 这里使用半透明的白色 */ rgba(255, 255, 255, 0.2)
    ),
    url("../../assets/images/kuluomi-task.png");
}
.shopping-bg {
  background: linear-gradient(
      rgba(255, 255, 255, 0.2),
      /* 这里使用半透明的白色 */ rgba(255, 255, 255, 0.2)
    ),
    url("../../assets/images/kuluomi-shopping.png");
}
.shopping-color {
  border: 2px solid #f2b275;
}

.custom-card {
  border-radius: 8px;
  padding: 12px 16px;
  color: #000;
  font-size: 16px;
  margin-bottom: 10px;

  background-blend-mode: lighten; /* 使用混合模式 */

  background-position: right 90px bottom; /* 定位到右下角 */
  background-repeat: no-repeat; /* 防止背景图片重复 */
  background-size: 55px;

  & > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 2;
  }
}
</style>
